package com.qf.channel;

import com.qf.entity.Msg;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@ChannelHandler.Sharable
@Order(50)
public class MsgHeartChannelHandler extends SimpleChannelInboundHandler<Msg> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Msg msg) throws Exception {
        if (msg.getType() == 0) {
            //心跳消息，回复心跳消息
            msg.setFrom(-1);
            ctx.writeAndFlush(msg);
        } else {
            ctx.fireChannelRead(msg);
        }
    }
}
